#include "firstdialog.h"
#include "ui_firstdialog.h"
#include <QDebug>

FirstDialog::FirstDialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::FirstDialog)
{
    ui->setupUi(this);
    btnGroup=new QButtonGroup();
    btnGroup->addButton(ui->radioButton,0);
    btnGroup->addButton(ui->radioButton_2,1);
    ui->radioButton->setChecked(true);




}

FirstDialog::~FirstDialog()
{
    delete ui;
    delete btnGroup;
}

DialogData &FirstDialog::getDialogData()
{
    return dd;
}

void FirstDialog::connectToMainWindow(MainWindow& w)
{
    QObject::connect(this->dd.getSendBus(),&SendBus::sendBelowSide,w.getGameScene().getChessData(),&ChessData::setGameBelow);
    QObject::connect(this->dd.getSendBus(),&SendBus::sendGameStart,w.getGameScene().getChessData(),&ChessData::setGameStart);
    QObject::connect(btnGroup,&QButtonGroup::buttonClicked,[this](QAbstractButton *button){
        int id= button->group()->checkedId();
        qDebug()<<"below select id:"<<id;
        this->dd.setBelowSide(id);
        emit dd.getSendBus()->sendBelowSide(id);
    });

}

void FirstDialog::on_buttonBox_accepted()
{
    dd.setGameStart(true);
    emit dd.getSendBus()->sendGameStart(true);
}

